<?php
session_start();

if(!isset($_SESSION['logged_in']))
{
	header ("Location: login.php");
}

?>
<!doctype html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>
			The Cobra Snake - ADMIN
		</title>
		<style type="text/css">
			
			body,td,th {
			font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
			font-size:10px;
			color:#999;
			background-color:#000;
			text-align:center
			}
			
			body {
			background-color:#000;
			margin:0
			}
			
			h2 {
			height:20px;
			clear:both
			}
			
			.removable_tag_list {
			height:75px;
			overflow:auto;
			list-style:none;
			border:none;
			margin:0;
			padding:0
			}
			
			#mainContainer {
			text-align:center;
			display:block
			}
			
			#editableGalleries {
			width:600px;
			float:none;
			position:absolute;
			top:650px;
			left:50%;
			margin-left:-300px;
			overflow:auto
			}
			
			#photosWithFields {
			width:680px;
			float:none;
			position:absolute;
			top:270px;
			left:50%;
			margin-left:-340px;
			overflow:hidden
			}
			
			#thumbsList,#galleryList,.topLinks, #deletedThumbsList {
			list-style:none;
			border:none;
			margin:0;
			padding:0;
			}
			
			#editableGalleries li {
			border:1px solid #000;
			float:left;
			margin:0 10px 10px 0
			}
			
			#photosWithFields li {
			border:1px solid #fff;
			float:none;
			
			display: -moz-inline-stack;
	        display: inline-block;
	        zoom: 1;
	        *display: inline;
			
			
			height:auto;
			width:200px;
			text-align:left;
			margin:0;
			padding:11px
			}
			
			#photosWithFields li ul li {
			border:none;
			float:none;
			margin-bottom:3px;
			height:16px;
			width:150px;
			padding:0
			}
			
			#guestCheck {
			display:none;
			height:400px;
			width:500px;
			position:fixed;
			left:50%;
			margin-left:-800px;
			margin-top:270px
			}
			
			#guestCheckDropTarget {
			background-color:red;
			position:fixed;
			left:50%;
			margin-left:-677px;
			margin-top:322px;
			height:394px;
			width:254px;
			text-align:center;
			display:none;
			overflow:visible
			}
			
			#guestCheckImg,#guestCheckFields {
			vertical-align:top;
			zoom:1;
			display:inline
			}
			
			#guestCheckFields {
			position:relative;
			width:auto;
			text-align:right;
			line-height:49px;
			overflow:hidden;
			margin-top:-20px
			}
			
			#guest_check_form span {
			line-height:normal
			}
			
			#guestCheckContent {
			width:100%;
			height:auto;
			display:block;
			margin-top:20px
			}
			
			#new_category_form {
			height:60px;
			border:solid 2px #DFDFDF;
			background-color:#eee;
			line-height:normal;
			padding:10px;
			position:relative;
			}
			
			#editBtn,#previewBtn {
			font-size:16px;
			font-weight:700
			}
			
			.editableGalleryThumb {
			cursor:pointer
			}
			
			.handle {
			cursor:url(images/moveCursor.png) 13 13s 13 13, auto
			}
			
			.removable_tag {
			background:#eee url(js/jquery.plupload.queue/img/delete.gif) no-repeat right top;
			cursor:pointer;
			margin-bottom:3px
			}
			
			.guest_check_form_input {
			width:99px;
			outline:none;
			height:16px;
			font-size:16px;
			font-weight:700;
			border:solid 2px #00fb34;
			padding:10px
			}
			
			.emptyInputWarning {
			border:solid 2px red;
			background:#FDD;
			color:#000
			}
			
			.photo_form,.removable_tag_list {
			width:190px
			}
			
			a:hover {
			color:red
			}
			
			a:active {
			color:#FF0
			}
			
			#gc_month,#gc_topcolor,#gc_bottomcolor {
			width:40px
			}
			
			#gc_year,#gc_day,#gc_topsize,#gc_bottomsize {
			width:15px
			}
			
			#gc_galleryname {
			width:141px
			}
			
			#html5_uploader {
			position:relative;
			left:50%;
			margin-left:-400px;
			margin-top:265px
			}
			
			.cobraButtonDynamic
			{
				height: 58px;
				width:auto;
				background: url("../img/btnLeft.png") no-repeat left top;				
				margin: 0;
				padding: 0;
				padding-left: 15px;
				
				
				display: -moz-inline-stack;
		        display: inline-block;
		        vertical-align: top;
		        zoom: 1;
		        *display: inline;

			}
			
			.cobraButtonDynamic a
			{
				height: 58px;
				width:auto;
				background: url("../img/btnRight.png") no-repeat right top;
				
				position: relative;
				
				display: -moz-inline-stack;
		        display: inline-block;
		        vertical-align: top;
		        zoom: 1;
		        *display: inline;
			}
			.cobraButtonDynamic a img
			{
				margin-top: 10px;
			}
			
			.reorder_handle {
			position:absolute;
			top:2px;
			left:2px;
			background:#aaa url(images/moveHandle.png) no-repeat 0 0;
			width:16px;
			height:16px;
			border:solid 1px #ccc
			}
			
			.deleteX
			{
				position:absolute;
				top:12px;
				left:185px;
				background:transparent url(images/delete.png) no-repeat 0 0;
				width:25px;
				height:30px;
				cursor: pointer;
			}
			
			
			#helperContainer {
			width:100px;
			height:66px;
			background-color:#000;
			display:none;
			padding:10px
			}
			
			#galleryInfoForm
			{
				position:fixed;
				top:270px;
				left:50%;
				margin-left:380px;
				height: 300px;
				width:300px;
				border: solid thin #fff;
				display:none;
			}
			
			#html5_uploader2 
			{
				position:relative;
				left:50%;
				margin-left:-250px;
			}
			
			#gc_gallerypath
			{
				font-style: italic;
				color: gray;
				font-size: 12px;
			}
			
			#deletedThumbsList
			{
				clear: both;
			}
			
			.undelete
			{
				cursor: pointer;
			}
			
			/* HEADER */
			
			
			
			#headerContainer {
			position:fixed;
			top:0;
			left:0;
			background-color:#000;
			height:auto;
			width:100%;
			text-align:center
			}
			
			#headerMenu {
			height:100px;
			width:790px;
			background:url(../img/headerBG.jpg) no-repeat 0 center;
			position:relative;
			left:50%;
			margin-left:-375px;
			margin-top:30px
			}
			
			#theCobraSnakeLogo {
			margin-top:60px
			}
			
			.navButtons {
			list-style:none;
			margin:0;
			padding:0
			}
			
			.navButtons li {
			width:166px;
			height:100px;
			float:left
			}
			
			.navButtons li img {
			margin-top:40px
			}
			
			.navButtons li:nth-child(3) {
			width:144px
			}
			
			.navButtons li:nth-child(4) {
			width:144px;
			text-align:center
			}
			
			.navButtons li:nth-child(4) img:nth-child(1) {
			margin-top:20px
			}
			
			.navButtons li:nth-child(4) img:nth-child(2) {
			margin-top:0
			}
			
			.search_input {
			margin-top:38px;
			width:85px;
			outline:none;
			height:18px;
			font-size:16px;
			font-weight:700;
			border:solid 3px red;
			padding:8px
			}
			
			#guest_check_form,#thumbsList li, #deletedThumbsList li {
			position:relative
			}
			
			a:link,a:visited {
			color:green
			}
			/* HEADER */
		</style>
		<link type="text/css" rel="stylesheet" href="css/syronex-colorpicker.css" />
		<!-- <link type="text/css" rel="stylesheet" href="css/jquery.miniColors.css" /> -->
		<link rel="stylesheet" href="js/jquery.plupload.queue/css/jquery.plupload.queue.css"
		type="text/css" media="screen" />
		<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js">
		                		                    
		</script>
		<script type="text/javascript" src="../js/jquery-ui-1.7.1.custom.min.js">
		                		                    
		</script>
		<script type="text/javascript" src="../js/functions.js">
		                		                    
		</script>
		<script type="text/javascript" src="js/plupload.js">
		                		                    
		</script>
		<script type="text/javascript" src="js/plupload.html5.js">
		                		                    
		</script>
		<script type="text/javascript" src="js/jquery.plupload.queue/jquery.plupload.queue.js">
		                		                    
		</script>
		<script type="text/javascript" src="js/syronex-colorpicker.js"></script>
		
		
	<script type="text/javascript" src="js/ui.core.js"></script>
	<script type="text/javascript" src="js/ui.draggable.js"></script>
	<script type="text/javascript" src="js/ui.droppable.js"></script>
		
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
		
		<!--<script type="text/javascript" src="js/jquery.miniColors.js"></script>
		
		<script src="js/cufon-yui.js" type="text/javascript"></script>
		<script src="js/TCS_400.font.js" type="text/javascript"></script>-->
		<script type="text/javascript">
			//Cufon.replace('body'); // Works without a selector engine
			//Cufon.replace('#sub1'); // Requires a selector engine for IE 6-7, see above
		</script>
		<!--[if IE]>
			<script type="text/javascript">
			function fixOutOfMemoryError() {
			  __flash_unloadHandler = function() {};
			  __flash_savedUnloadHandler = function() {};
			}
			window.attachEvent("onbeforeunload", fixOutOfMemoryError);
			</script>
		<![endif]-->
	</head>
	<body>
		<div id="mainContainer">
				<div id="html5_uploader" style="width: 795px; height: 400px;">
					You browser doesnt support native upload. Try The latest Firefox or Safari.
				</div>
				<div id="guestCheck">
					<span id="editBtn" class="cobraButtonDynamic"><a href="#"><img src="../pngfont.php?bgcolor=ffa1a2&color=000&size=14&font=fonts/TCS2.ttf&text=EDIT GALLERY " alt="EDIT" border="0"></a></span><span id="previewBtn" class="cobraButtonDynamic"><a href="#"><img src="../pngfont.php?bgcolor=ffa1a2&color=000&size=14&font=fonts/TCS2.ttf&text=PREVIEW GALLERY " alt="PREVIEW" border="0"></a></span><!-- <button id="editBtn"><img src="../pngfont.php?bgcolor=ddd&color=f00&size=14&font=fonts/TCS2.ttf&text=EDIT GALLERY " alt="EDIT" border="0"></button><button id="previewBtn"><img src="../pngfont.php?bgcolor=ddd&color=f00&size=14&font=fonts/TCS2.ttf&text=PREVIEW GALLERY" alt="PREVIEW" border="0"></button> -->
					<div id="guestCheckContent">
						<div id="flashGuestCheck">The Guest Check Maker requires JavaScript and the Flash Player.
							<a href="http://www.adobe.com/go/getflashplayer/">Get Flash.</a>
						</div> 
						<!--
<img id="guestCheckImg" src="" border="0" />
						<div id="guestCheckFields"><form class="guest_check_form">
								<span class="publishing">HIDE GALLERY: <input class="publishing_radio_buttons" type="radio" name="public" value="NO" checked="true" id="gc_private" />   SHOW GALLERY: <input class="publishing_radio_buttons" type="radio" name="public" value="YES" id="gc_public"/></span><br />
								<span><input class="guest_check_form_input"  type="text" name="month" value="JAN" id="gc_month" />  /  <input  class="guest_check_form_input"  type="text" name="day" value="01" id="gc_day" />  /  <input  class="guest_check_form_input"  type="text" name="year" value="99" id="gc_year" /></span><br />
								
								<span><input  class="guest_check_form_input"  type="text" name="topText" value="TOP TEXT" id="gc_toptext" /> <input  class="guest_check_form_input"  type="text" name="topSize" value="11"  id="gc_topsize" /> <input  class="guest_check_form_input colors"  type="hidden" name="topColor" value="#000000"  id="gc_topcolor" /><span class="color_paletteA" rel="gc_topcolor"></span></span><br />
								
								<span><input  class="guest_check_form_input"  type="text" name="bottomText" value="BOTTOM TEXT"  id="gc_bottomtext" /> <input  class="guest_check_form_input"  type="text" name="bottomSize" value="11"  id="gc_bottomsize" /><input  class="guest_check_form_input colors"  type="hidden" name="bottomColor" value="#000000"  id="gc_bottomcolor" /><span class="color_paletteB" rel="gc_bottomcolor"></span></span><br />
								
								<span><input  class="guest_check_form_input"  type="text" name="galleryName" value=""  id="gc_galleryname" /> <span id="gc_gallerypath"></span></span><br />
								
								<span><select name="category" id="categorySelector"><option value="new">CREATE A NEW ONE…</option></select></span>					
							</form>
							<form id="new_category_form">
							NEW CITY: <input  type="text" name="category"  id="nc_category" /><input  class="categoryColor"  type="hidden" name="color" value="#000000"  id="nc_color" /><span class="color_paletteC" rel="nc_color"> </span><input type="submit" value="CREATE" />
							</form>
						</div>
-->
					</div>
				</div><br />
				<div id="galleryInfoForm">
					<input type="text" name="galleryName" value=""  id="gc_galleryname" />
						<span id="gc_gallerypath"></span><br />
						<span class="publishing">HIDE GALLERY: <input class="publishing_radio_buttons" type="radio" name="public" value="NO" checked="true" id="gc_private" />
						SHOW GALLERY: <input class="publishing_radio_buttons" type="radio" name="public" value="YES" id="gc_public"/></span>
						<span><select name="category" id="categorySelector"><option value="new">CREATE A NEW ONE…</option></select></span>
						<form id="new_category_form">
							NEW CITY: <input  type="text" name="category"  id="nc_category" /><input  class="categoryColor"  type="hidden" name="color" value="#000000"  id="nc_color" /><span class="color_paletteC" rel="nc_color"> </span><input type="submit" value="CREATE" />
						</form>
				</div>
				<div id="photosWithFields">
					<img src="../pngfont.php?bgcolor=000000&color=f00&size=17&font=fonts/TCS2.ttf&text=DRAG PHOTOS " alt="DRAG PHOTOS TO CHANGE ORDER" border="0">
					<img src="../pngfont.php?bgcolor=000000&color=f00&size=17&font=fonts/TCS2.ttf&text=TO CHANGE ORDER " alt="DRAG PHOTOS TO CHANGE ORDER" border="0"><br />
					
					<ul id="thumbsList" ></ul><br />	
					<img id="deletedHeader" src="../pngfont.php?bgcolor=000000&color=f00&size=17&font=fonts/TCS2.ttf&text=DELETED PHOTOS " alt="DELETED PHOTOS" border="0" /><br />	
					<ul id="deletedThumbsList" ></ul><br />	
							
					<div id="html5_uploader2" style="width: 500px; height: 400px;">
						You browser doesnt support native upload. Try The latest Firefox or Safari.
					</div><br />
				</div><br />
				<div id="editableGalleries">
					<img class="gallerySectionLabel" src="../pngfont.php?bgcolor=000000&color=f00&size=20&font=fonts/TCS2.ttf&text=EDIT ANY " alt="EDIT ANY GALLERY BELOW" border="0">
					<img class="gallerySectionLabel" src="../pngfont.php?bgcolor=000000&color=f00&size=20&font=fonts/TCS2.ttf&text=GALLERY BELOW " alt="EDIT ANY GALLERY BELOW" border="0"><br />
					<ul id="galleryList" />
				</div>
			</div>
			
					<div id="guestCheckDropTarget">
						<img style="margin-top:150px;" src="../pngfont.php?bgcolor=ff0000&color=000&size=20&font=fonts/TCS2.ttf&text=DROP " alt="DROP IMAGE HERE" border="0"><br />
						<img src="../pngfont.php?bgcolor=ff0000&color=000&size=20&font=fonts/TCS2.ttf&text=IMAGE " alt="DROP IMAGE HERE" border="0"><br />
						<img src="../pngfont.php?bgcolor=ff0000&color=000&size=20&font=fonts/TCS2.ttf&text=HERE " alt="DROP IMAGE HERE" border="0">
					</div>
			<div id="headerContainer">
				<a href="http://thecobrasnake.com/" target="_self"><img id="theCobraSnakeLogo" src="../pngfont.php?bgcolor=000000&color=fffb00&size=28&font=fonts/TCS2.ttf&text=THE COBRA SNAKE " alt="THE COBRA SNAKE" border="0"></a>
				<div id="headerMenu">
					<ul class="navButtons">
						<li><a href="http://thecobrasnake.com/" target="_self"><img src="../pngfont.php?bgcolor=f6f9fd&color=ff0000&size=11&font=fonts/TCS2.ttf&text=PHOTOS " alt="THE COBRA SNAKE" border="0"></a></li>
						<li><a href="http://shop.thecobrasnake.com/collections/cool-stuff" target="_self"><img src="../pngfont.php?bgcolor=f6f9fd&color=7dfc7d&size=11&font=fonts/TCS2.ttf&text=STORE " alt="THE COBRA SNAKE" border="0"></a></li>
						<li><a href="#" target="_self"><img class="search_label" src="../pngfont.php?bgcolor=f6f9fd&color=c0c0c0&size=11&font=fonts/TCS2.ttf&text=SEARCH " alt="THE COBRA SNAKE" border="0"></a><input type="text" class="search_input"></input></li>
						<?php 
						if(isset($_SESSION['logged_in_admin']))
						{
							?>
							<li><a href="create_user.php" target="_self"><img src="../pngfont.php?bgcolor=f6f9fd&color=7dc9ff&size=11&font=fonts/TCS2.ttf&text=MANAGE " alt="THE COBRA SNAKE" border="0"><img src="../pngfont.php?bgcolor=f6f9fd&color=7dc9ff&size=11&font=fonts/TCS2.ttf&text=LOGINS " alt="THE COBRA SNAKE" border="0"></a></li>
							<?php
						}else
						{
							?>
							<li>&nbsp;</li>
							<?php
						}
						?>
						<li><a href="./logout.php" target="_self"><img src="../pngfont.php?bgcolor=f6f9fd&color=ffc77a&size=11&font=fonts/TCS2.ttf&text=LOG OUT " alt="THE COBRA SNAKE" border="0"></a></li>
					</ul>
				</div>
			</div>
			<div id="helperContainer">yo yo yo</div>
		<script type="text/javascript">
			var authorId = <?= $_SESSION['authorId'];?>;
			var today = new Date();
			var photoGalleryId = 0;
			// initial values for the guest check
			var newfilename = "covers/0.jpg";
			var photoName = "000";
			var month = monthFromNum(today.getMonth());
			var day = today.getDate();
			var year = today.getFullYear().toString().substr(2, 2);
			var topText = "TOP TEXT";
			var bottomText = "BOTTOM TEXT";
			var topSize = 11;
			var bottomSize = 11;
			var topColor = "#000000";
			var bottomColor = "#000000";
			var galleryName = "new gallery";
			$(function () {
			        $('.search_input').hide();
			        $('.search_input').val("");
			        $("#photosWithFields").hide();
			        $("#gc_month").val(month);
			        $("#gc_day").val(day);
			        $("#gc_year").val(year);
			        $("#gc_toptext").val(topText);
			        $("#gc_topsize").val(topSize);
			        $("#gc_topcolor").val(topColor);
			        $("#gc_bottomtext").val(bottomText);
			        $("#gc_bottomsize").val(bottomSize);
			        $("#gc_bottomcolor").val(bottomColor);
			        $("#gc_galleryname").val(galleryName);
			        $("#gc_gallerypath").text("http://thecobrasnake.com/"+$('#gc_galleryname').val()+"/"+photoGalleryId+".jpg");
			        webservice.photos.getGalleriesByAuthorId(authorId, function (galleriesJSON) {
			                if (galleriesJSON) {
			                        var jList = $("#galleryList");
			                        // Loop over each value in the array.
			                        $.each(galleriesJSON, function (intIndex, objValue) {
			                                var htmlStr = "";
			                                htmlStr += '<img src="../timthumb.php?src=' + objValue.cover_url + '&w=127&h=197" border="0" />';
			                                jList.append($("<li class='editableGalleryThumb' rel='" + objValue.id + "'>" + htmlStr + "</li>"));
			                        });
			                        if ($("#galleryList li").length < 1) {
			                                $(".gallerySectionLabel").hide();
			                        }
			                }
			        });
			        
			        showGuestCheck();
			  
			        $('.color_paletteC').colorPicker(
					{			
					  defaultColor:0,
					  color: ["#000000", "#e500e2","#ffb400","#008aff","#00d40f","#f0ff00","#ff0000"],
					  extra: $(".color_paletteC").attr('rel'),
					  click:function(c, o){
					    //alert(c);
					   // alert(  o  );
					    $("#"+o).val(c);
					  }
					});
					
			        $(".deleteX").live("click", function(){
			        	var thumbData = $(this).attr("rel");
			        	var thumbId = thumbData.split(",")[0];
			        	var thumbURL = thumbData.split(",")[1];
			        	
			        	$(this).closest("li").remove();
			        	
			        	$("#deletedThumbsList").append( makeUndeletableThumb( thumbURL, thumbId ) );
			        	
			        	webservice.photos.updatePhotoPublic(thumbId, 0);
			        });
			        
			        
			        $(".undelete").live("click", function(){
			        	var thumbData = $(this).attr("rel");
			        	var thumbId = thumbData.split(",")[0];
			        	var thumbURL = thumbData.split(",")[1];
			        	
			        	$(this).remove();
			        	
			        	$("#thumbsList").append( makeDraggabeThumb( thumbURL, thumbId, $("#thumbList li").length ) );
			        	
			        	makeImagesDraggable();
			        	
			        	webservice.photos.updatePhotoPublic(thumbId, 1);
			        });
			        
			        
			        $('#gc_galleryname').keyup(function(){
			        	webservice.photos.setGalleryName(photoGalleryId, $('#gc_galleryname').val());
			        	
			        	$("#gc_gallerypath").text("http://thecobrasnake.com/"+$('#gc_galleryname').val()+"/"+photoGalleryId+".jpg");
			        	
			        });
			        
			        $('.search_label').click(function () {
			                $('.search_label').hide();
			                $('.search_input').show();
			        });
			        $('.search_input').change(function () {
			                window.location = "../gallery.php?search=" + $(this).val();
			        });
			        $("#editBtn").click(function () {
			                $("#guestCheckFields").show();
			                $(".photo_form").show();
			                $("#editBtn").hide();
			                $("#previewBtn").show();
			                $(".reorder_handle").show();
			        });
			        $("#previewBtn").click(function () {
			                $("#guestCheckFields").hide();
			                $(".photo_form").hide();
			                $("#editBtn").show();
			                $("#previewBtn").hide();
			                $(".reorder_handle").hide();
			        });
			        
			        
			        $('#new_category_form').submit(function () {
			                var targetForm = $($(this).closest("form"));
			                var categoryData = new Array();
			                $.each(targetForm.serializeArray(), function (i, field) {
			                        categoryData[field.name] = field.value;
			                });
			                var title = categoryData.category;
			                var color = categoryData.color;
			                $("#nc_category").val("");
			                $("#nc_color").val("#000000");
			                $("#new_category_form").hide();
			                webservice.photos.saveNewCategory(title, color, function (newCategoryId) {
			                        // create the category and when it returns:
			                        $('#categorySelector').append($('<option>', {
			                                value: newCategoryId
			                        }).text(title).css({
			                                "background-color": color
			                        }));
			                        $("#categorySelector").val(newCategoryId);
			                        //SAVE GALLERY CATEGORY	
			                        categorySelected();
			                });
			                return false;
			        });
			        $("#new_category_form").hide();
			        // get list of cities and add them to the drop down 
			        webservice.photos.getAllCategories(function (categoriesJSON) {
			                $.each(categoriesJSON, function (intIndex, objValue) {
			                		$('#categorySelector').prepend($('<option />', {
			                                value: objValue.id
			                        }).text(objValue.title).css({
			                                "background-color": objValue.color
			                        }));
			                });
			                $('#categorySelector').prepend($('<option>', {
			                        value: ""
			                }).text("SELECT A CITY…"));
			                $("#categorySelector").val('');
			        });
			        $('#categorySelector').change(categorySelected);
			
			        function categorySelected() {
			                //alert( $("#categorySelector option:selected").val() );
			                var selectedValue = $("#categorySelector option:selected").val();
			                if (selectedValue == "new") {
			                        // show new category form
			                        $("#new_category_form").show();
			                }
			                else {
			                        // save category
			                        webservice.photos.saveGalleryCategory(photoGalleryId, selectedValue, function (msg) { 
			                        	/* alert(msg); */
			                        });
			                }
			        }
			        $(".publishing_radio_buttons").change(function () {
			                var publicStatus = 0;
			                switch ($(this).val()) {
			                case "YES":
			                        publicStatus = 1;
			                        break;
			                case "NO":
			                        publicStatus = 0;
			                        break;
			                }
			                webservice.photos.setGalleryPublicStatus(photoGalleryId, publicStatus, function (msg) { /* alert(msg); */
			                });
			        });
			        // Setup html5 uploader
			        $("#html5_uploader").pluploadQueue({
			                // General settings
			                runtimes: 'html5',
			                url: 'upload.php',
			                max_file_size: '20mb',
			                chunk_size: '1mb',
			                unique_names: true,
			                filters: [{
			                        title: "Image files",
			                        extensions: "jpg,gif,png"
			                }],
			                // Resize images on clientside if we can
			                resize: {
			                        width: 1067,
			                        height: 711,
			                        quality: 90
			                }
			        });
			        
			        $("#html5_uploader2").pluploadQueue({
			                // General settings
			                runtimes: 'html5',
			                url: 'upload.php',
			                max_file_size: '20mb',
			                chunk_size: '1mb',
			                unique_names: true,
			                filters: [{
			                        title: "Image files",
			                        extensions: "jpg,gif,png"
			                }],
			                // Resize images on clientside if we can
			                resize: {
			                        width: 1067,
			                        height: 711,
			                        quality: 90
			                }
			        });
			        var uploader = $("#html5_uploader").pluploadQueue();
			        uploader.bind('UploadComplete', function (uploader, filez) {
			                //alert('UPLOADED files: ' + filez.length);
			                // first create a gallery
			                webservice.photos.createGallery(authorId, function (galleryId) {
			                        //alert("GALLERY CREATED WITH ID: "+galleryId);
			                        photoGalleryId = galleryId;
			                        // create a list of file names
			                        fileList = "";
			                        for (i = 0; i < filez.length; i++) {
			                                if (i == filez.length - 1) {
			                                        fileList += filez[i].id;
			                                }
			                                else {
			                                        fileList += filez[i].id + ",";
			                                }
			                        }
			                        // add them to the gallery 
			                        webservice.photos.addPhotos(galleryId, fileList, function (message) {
			                                // get photos with their corresponding id's
			                                showEditableGallery(galleryId);
			                        });
			                });
			        });
			        
			        var secondUploader = $("#html5_uploader2").pluploadQueue();
			        secondUploader.bind('UploadComplete', function (uploader, filez) {
			                //alert('UPLOADED files: ' + filez.length);
			              	 fileList = "";
	                        for (i = 0; i < filez.length; i++) {
	                                if (i == filez.length - 1) {
	                                        fileList += filez[i].id;
	                                }
	                                else {
	                                        fileList += filez[i].id + ",";
	                                }
	                        }
	                        // add them to the gallery 
	                        webservice.photos.addPhotos(photoGalleryId, fileList, function (message) {
	                                // get photos with their corresponding id's
	                                showEditableGallery(photoGalleryId);
	                        });
			              
			        });
			        $("#thumbsList").sortable({
			                handle: '.handle',
			                update: function () {
			                        var orderDataArr = new Array();
			                        $("#thumbsList li").each(function (index) {
			                                orderDataArr.push(index + ': ' + $(this).attr("rel"));
			                        });
			                        webservice.photos.setNewGalleryOrder(photoGalleryId, orderDataArr.toString(), function (msg) {
			                                //alert(msg);
			                        });
			                }
			        });
			        $('.editableGalleryThumb').live('click', function () {
			                var targetGalleryId = $(this).attr('rel');
			                showEditableGallery(targetGalleryId);
			        });
			        $('.photo_form_input').live('change', function () {
			                var photo = {};
			                $.each($($(this).closest("form")).serializeArray(), function (i, field) {
			                        photo[field.name] = field.value;
			                        //alert(field.name + " = " + field.value);
			                });
			                photo.public = ($(this).closest("form").find(".publishCheckbox").attr('checked')) ? 1 : 0;
			                webservice.photos.updatePhotoProperties(photo.id, photo.tags, photo.public, function (msg) {
			                        var cleared = false;
			                        $.each(msg, function (intIndex, objValue) {
			                                var tagList = $("#tags_" + objValue.photo_id);
			                                var tagsInput = $("#tags_input_" + objValue.photo_id);
			                                tagsInput.val("");
			                                if (!cleared) {
			                                        cleared = true;
			                                        tagList.html("");
			                                }
			                                tagList.append($("<li class='removable_tag' rel='" + objValue.id + "'>" + objValue.tag + "</li>"));
			                        });
			                });
			        });
			        $('.guest_check_form_input').live('keyup', guestCheckUpdate);
			        $('form').live('submit', function (e) {
			                e.preventDefault();
			        });
			        $('.photo_form_cover').live('change', function () {
			                $('input[type=radio]').each(function () {
			                        $(this).attr('checked', false);
			                });
			                $(this).attr('checked', true);
			                photoName = $(this).attr('rel');
			                webservice.photos.makeGuestCheck(photoGalleryId, photoName, month, day, year, topText, bottomText, topSize, bottomSize, topColor, bottomColor, function (updatedFileName) {
			                        $("#guestCheckImg").attr('src', updatedFileName);
			                });
			        });
			        $('.removable_tag').live('click', function () {
			                var tagToRemove = $(this);
			                webservice.photos.removeTag($(this).attr('rel'), function (msg) {
			                        tagToRemove.remove();
			                });
			        });
			});
			function guestCheckUpdate() {
	                var guestCheckData = {};
	                var doGuestCheckUpdate = true;
	                var targetForm = $($(this).closest("form"));
	                $.each(targetForm.serializeArray(), function (i, field) {
	                        guestCheckData[field.name] = field.value;
	                        if (field.value.length < 1) {
	                                doGuestCheckUpdate = false;
	                        }
	                });
	                targetForm.find(':input').each(function (i) {
	                        if ($(this).val() == "") {
	                                $(this).addClass('emptyInputWarning');
	                        }
	                        else {
	                                $(this).removeClass('emptyInputWarning');
	                        }
	                });
	                if (doGuestCheckUpdate) {
	                        month = (guestCheckData.month) ? guestCheckData.month : "00";
	                        day = (guestCheckData.day) ? guestCheckData.day : "00";
	                        year = (guestCheckData.year) ? guestCheckData.year : "00";
	                        topText = (guestCheckData.topText) ? guestCheckData.topText : " ";
	                        bottomText = (guestCheckData.bottomText) ? guestCheckData.bottomText : " ";
	                        topSize = (guestCheckData.topSize) ? guestCheckData.topSize : "10";
	                        bottomSize = (guestCheckData.bottomSize) ? guestCheckData.bottomSize : "10";
	                        topColor = (guestCheckData.topColor) ? guestCheckData.topColor : "#000000";
	                        bottomColor = (guestCheckData.bottomColor) ? guestCheckData.bottomColor : "#000000";
	                        galleryName = (guestCheckData.galleryName) ? guestCheckData.galleryName : topText + " " + bottomText;
	                        $("#gc_month").val(month);
	                        $("#gc_day").val(day);
	                        $("#gc_year").val(year);
	                        $("#gc_toptext").val(topText);
	                        $("#gc_topsize").val(topSize);
	                        $("#gc_topcolor").val(topColor);
	                        $("#gc_bottomtext").val(bottomText);
	                        $("#gc_bottomsize").val(bottomSize);
	                        $("#gc_bottomcolor").val(bottomColor);
	                        webservice.photos.makeGuestCheck(photoGalleryId, photoName, month, day, year, topText, bottomText, topSize, bottomSize, topColor, bottomColor, function (updatedFileName) {
	                                $("#guestCheckImg").attr('src', updatedFileName);
	                        });
	                        // save the date and name of the gallery
	                        webservice.photos.saveGalleryData(photoGalleryId, month, day, year, galleryName, topText, bottomText, topColor, bottomColor, function (msg) {
	                                //alert(msg);
	                        });
	                }
	        }
	        
	        function makeDraggabeThumb(url, id, index)
	        {
	        	var htmlStr = "";
                
                htmlStr += '<img src="../timthumb.php?src=photographs/' + url + '.JPG&w=200&h=133" rel="' + url + '" border="0" class="draggableImage" />';
                htmlStr += '<form class="photo_form">';
                htmlStr += '<input class="" type="hidden" name="id" value="' + id + '"/>';
                htmlStr += 'ENTER TAGS HERE: <input id="tags_input_' + id + '" class="photo_form_input" type="text" name="tags" />';
                htmlStr += '<ul class="removable_tag_list" id="tags_' + id + '"></ul>';
                htmlStr += '</form>';
                htmlStr += '<div class="reorder_handle handle">&nbsp;</div>';
                htmlStr += '<div class="deleteX" rel="' + id + ','+url+'">&nbsp;</div>';
	        	
	        	return $("<li id='listItem_" + index + "' rel='" + id + "'>" + htmlStr + "</li>");
	        }
	        
	        function makeUndeletableThumb(url, id)
	        {
	        	return $('<img class="undelete" src="../timthumb.php?src=photographs/' + url + '.JPG&w=200&h=133" rel="' + id + ',' + url + '" border="0" alt="CLICK TO RESTORE" />');
	        }
	        
			function showEditableGallery(galleryId) {
			        $("#editableGalleries").hide();
			        $("#editBtn").hide();
			        $("#previewBtn").show();
			        photoGalleryId = galleryId;
			        webservice.photos.getGalleryImages(galleryId, function (photosJSON) {
			                $("#photosWithFields").show();
			                $("#thumbsList li").remove();
			                var jList = $("#thumbsList");
			                // Loop over each value in the array.
			                
			                
			                $.each(photosJSON, function (intIndex, objValue) {
			                        
			                        if(objValue.public == "1")
			                        {
			                        	jList.append( makeDraggabeThumb(objValue.url, objValue.id, intIndex) );
			                        }else
			                        {
			                        	$("#deletedThumbsList").append( makeUndeletableThumb(objValue.url, objValue.id) );
			                        }
			                        
			                        
			                        
			                        if (intIndex == 0) {
			                                photoName = objValue.url;
			                                $("#html5_uploader").hide();
			                                //getGalleryInfo
			                                webservice.photos.getGalleryData(photoGalleryId, function (dataJSON) {
			                                        if (dataJSON[0].cover_url != "") {
			                                                $("#guestCheck").show();
			                                				$("#galleryInfoForm").show();
			                                				$("#html5_uploader2").show();
			                                                //$("#guestCheckImg").attr('src', "../" + dataJSON[0].cover_url);
			                                                var dateStr = dataJSON[0].date;
			                                                var dateArr = dateStr.split('-');
			                                                month = monthFromNum(parseInt(dateArr[1]) - 1);
			                                                day = dateArr[2];
			                                                year = dateArr[0].substr(2);
			                                                topText = dataJSON[0].top_text;
			                                                bottomText = dataJSON[0].bottom_text;
			                                                topSize = 11;
			                                                bottomSize = 11;
			                                                topColor = dataJSON[0].top_color;
			                                                bottomColor = dataJSON[0].bottom_color;
			                                                galleryName = dataJSON[0].name;
			                                                $("#gc_public").attr('checked', (dataJSON[0].public == '1'));
			                                                $("#gc_private").attr('checked', (dataJSON[0].public == '0'));
			                                                $("#gc_month").val(month);
			                                                $("#gc_day").val(day);
			                                                $("#gc_year").val(year);
			                                                $("#gc_toptext").val(topText);
			                                                $("#gc_topsize").val(topSize);
			                                                $("#gc_topcolor").val(topColor);
			                                                $("#gc_bottomtext").val(bottomText);
			                                                $("#gc_bottomsize").val(bottomSize);
			                                                $("#gc_bottomcolor").val(bottomColor);
			                                                $("#gc_galleryname").val(galleryName);
			                                                $("#gc_gallerypath").text("http://thecobrasnake.com/"+$('#gc_galleryname').val()+"/"+photoGalleryId+".jpg");
			                                                $("#categorySelector").val(dataJSON[0].category_id);
			                                                $('.photo_form_input').trigger('change');
			                                        }
			                                        else {
			                                                webservice.photos.makeGuestCheck(photoGalleryId, photoName, month, day, year, topText, bottomText, topSize, bottomSize, topColor, bottomColor, function (updatedFileName) {
			                                                        $("#guestCheck").show();
			                                                        $("#galleryInfoForm").show();
			                                						$("#html5_uploader2").show();
			                                				
			                                                        //$("#guestCheckImg").attr('src', updatedFileName);
			                                                });
			                                        }
			                                });
			                        }
			                });
			                
			                
			                
			                makeImagesDraggable();
			                
			                
			                
			        });
			}
			
			function makeImagesDraggable()
			{
				$(".draggableImage").draggable({
	                    opacity: .75,
	                    cursor: 'move',
	                    atCursor: {
	                            left: 0
	                    },
	                    appendTo: '#guestCheckDropTarget',
	                    scroll: false,
	                    helper: function () {
	                            return $("#helperContainer");
	                    },
	                    start: function (event, ui) {
	                            $('#guestCheckDropTarget').show();
	                            $("#helperContainer").show();
	                            $("#helperContainer").html('');
	                            $("#helperContainer").html($('<img src="../timthumb.php?src=photographs/' + $(this).attr("rel") + '.JPG&w=100&h=66" border="0" rel="' + $(this).attr("rel") + '" />'));
	                    },
	                    stop: function (event, ui) {
	                            $('#guestCheckDropTarget').hide();
	                            $('body').append($('<div id="helperContainer">...</div>'));
	                    }
	            });
	            $("#guestCheckDropTarget").droppable({
	                    drop: function (event, ui) {
	                            //alert("DROPPED: " + ui.helper.find('img').attr('rel'));
	                            
	                            $('#flashGuestCheck').get(0).eiDataReceiver( {image: ui.helper.find('img').attr('rel') } );
	                            
	                            
	                    }
	            });
			}
			
			function getGalleryId()
			{
				return photoGalleryId;
			}
			function monthFromNum(monthNum) {
			        var month = new Array(12);
			        month["00"] = "JAN";
			        month[0] = "JAN";
			        month[1] = "FEB";
			        month[2] = "MAR";
			        month[3] = "APR";
			        month[4] = "MAY";
			        month[5] = "JUN";
			        month[6] = "JUL";
			        month[7] = "AUG";
			        month[8] = "SEP";
			        month[9] = "OCT";
			        month[10] = "NOV";
			        month[11] = "DEC";
			        return month[monthNum];
			}
			
			function dump(obj) {
			        var out = '';
			        for (var i in obj) {
			                out += i + ": " + obj[i] + "\n";
			        }
			}
			
			function showGuestCheck(galleryId, month, day, year, topText, bottomText)
			{
				var flashvars = {};
				flashvars.galleryURL = "gallery.xml";
				flashvars.galleryId = galleryId; 
				flashvars.month = month;
				flashvars.day = day;
				flashvars.year = year;
				flashvars.topText = topText; 
				flashvars.bottomText = bottomText;
				
				var params = {};
				params.bgcolor = "222222";
				params.allowfullscreen = true;
				params.allowscriptaccess = "always";
				
				var attributes = {};
				attributes.id = "flashGuestCheck";  
				attributes.name = "flashGuestCheck";
				
				swfobject.embedSWF("guestCheck.swf", "flashGuestCheck", "254", "394", "9.0.124", false, flashvars, params, attributes);
				
			}
			        
					
		</script>
	</body>

</html>